/*--------------------------------------------------------------*
 * Creat Date: 2015/7/20 										*
 * Modify    : 
 *                                     
 *--------------------------------------------------------------*/
 #include "at24xx.h"
 
uint8_t at24Write(uint32_t DataAdd,uint16_t Len,uint8_t  *Rsc)
{
	uint8_t Sla;
	uint16_t Sda;
	uint8_t SdaType;
	
#if (EEP_ADDR_TYPE & 0x01) == 0	
	SdaType = 1;                       //one byte sda
	Sda  = DataAdd & 0xFF;
	DataAdd     >>= 8; 
#else
	SdaType = 2;                      //Two byte sda
	Sda  = DataAdd & 0xFFFF;
	DataAdd     >>= 16; 
#endif

#if (EEP_EEP_ADDR_TYPE & EEP_INTER_SLA_MASK) == 0
	Sla = EEP_CHIP_ADDR;
#else
	Sla = EEP_CHIP_ADDR | ((EEP_EEP_ADDR_TYPE & EEP_INTER_SLA_MASK) & (DataAdd << 1));
#endif
	
	while(I2C1_MasterSendBytes(Sla,Sda,SdaType,Rsc,Len) != I2C_ERROR_NULL);
	return I2C_ERROR_NULL;
}



uint8_t at24Read(uint32_t DataAdd,uint16_t Len,uint8_t *Des)
{
	uint8_t Sla;
	uint16_t Sda;
	uint8_t SdaType;
	
#if (EEP_ADDR_TYPE & 0x01) == 0	
	SdaType = 1;                       //one byte sda
	Sda  = DataAdd & 0xFF;
	DataAdd     >>= 8; 
#else
	SdaType = 2;                      //Two byte sda
	Sda  = DataAdd & 0xFFFF;
	DataAdd     >>= 16; 
#endif

#if (EEP_EEP_ADDR_TYPE & EEP_INTER_SLA_MASK) == 0
	Sla = EEP_CHIP_ADDR;
#else
	Sla = EEP_CHIP_ADDR | ((EEP_EEP_ADDR_TYPE & EEP_INTER_SLA_MASK) & (DataAdd << 1));
#endif
	
	while(I2C1_MasterReadBytes(Sla,Sda,SdaType,Des,Len) != I2C_ERROR_NULL);
	return I2C_ERROR_NULL;

} 

